/* Copyright Thanh-Trung Pham, JAIST, 2013 */

package jp.ac.jaist.input;

import jp.ac.jaist.MVPStructureType;
import org.apache.commons.lang3.StringUtils;

import java.util.*;

/**
 *
 * @author Thanh-Trung Pham
 */
public class RMPIErrorPropertyVectorWrapper {
    private static final String RMPI_COMMA = ",";

    private Map<Set<String>, Double> m_oErrorPropertyVector = new HashMap<Set<String>, Double>();

    /**
     * The constructor.
     * @param errorPropertyVector the error property vector from the input model.
     */
    public RMPIErrorPropertyVectorWrapper(MVPStructureType.ErrorPropertyVector errorPropertyVector) {
        for(MVPStructureType.ErrorPropertyVector.ForErroneousOutput oForErroneousOutput: errorPropertyVector.getForErroneousOutputArray()){
            Set<String> oSetOfOutputFailures = new HashSet<String>();
            String[] oOutputFailures = StringUtils.split(oForErroneousOutput.getInvolvedFailures(), RMPI_COMMA);
            oSetOfOutputFailures.addAll(Arrays.asList(oOutputFailures));

            m_oErrorPropertyVector.put(oSetOfOutputFailures, oForErroneousOutput.getProbability());
        }
    }

    /**
     * Get the error property probability for the given erroneous output.
     * @param erroneousOutput the erroneous output of propagating failure types.
     * @return the error property probability for the given failure type.
     */
    public double getProbability(Set<String> erroneousOutput){
        if(m_oErrorPropertyVector.containsKey(erroneousOutput)){
            return m_oErrorPropertyVector.get(erroneousOutput);
        }

        return 0;
    }


}
